<%@page import="util.PreHandle,pojo.Student"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'DoInsert.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>


	<%
		request.setCharacterEncoding("utf-8");
		String sql = "insert into student (sname,sex,gradeid,telephone,fromcity,pass,enterdate,birthday) values(?,?,?,?,?,?,now(),date_format(?,'%Y-%m-%d'))";
		Connection con = PreHandle.getConnection();
		PreparedStatement pstmt = null;
		ResultSet res = null;
		pstmt = con.prepareStatement(sql);
		int index = 1;
		pstmt.setString(index++, request.getParameter("sname"));
		pstmt.setString(index++, request.getParameter("sex"));
		pstmt.setInt(index++, Integer.parseInt(request.getParameter("gradeid")));
		pstmt.setString(index++, request.getParameter("telephone"));
		pstmt.setString(index++, request.getParameter("fromcity"));
		pstmt.setString(index++, request.getParameter("pass"));
		pstmt.setString(index++, request.getParameter("birthday"));
		if (pstmt.executeUpdate() == 1) {
		session.setAttribute("name", request.getParameter("sname"));
			response.sendRedirect("Congratuation.jsp");
			return;
		}
		response.sendRedirect("register.jsp");
	%>

</body>
</html>
